package org.ling.xuan.action.pdm;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.ling.xuan.condition.LxCondition;
import org.ling.xuan.dao.ProjectDao;
import org.ling.xuan.dialog.ProjectSettingDialog;
import org.ling.xuan.util.LoggerUtil;
import org.ling.xuan.util.LxOptional;

/**
 * lx添加项目操作
 *
 * @author liting50684
 * @date 2023/08/01
 */
public class LxPdmClassifyAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        Project project = e.getProject();
        String basePath = LxOptional.of(e, c -> c.getProject().getBasePath()).orElse("");
        ProjectSettingDialog settingDialog = new ProjectSettingDialog(project, true, basePath);
        if (settingDialog.showAndGet()) {
            ProjectDao.updateSetting(basePath, settingDialog.getSetting());
            LoggerUtil.log(e.getProject(), "项目添加成功:{}", project.getName());
        }
    }

}
